{% comment %}
<!--
  Copyright (C) 2008 ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
  - http://heavyz.blogspot.com/
  - http://buggarden.blogspot.com/

  This template displays a thread. It requires that the following variables be set:
  - user   : (optional) the current user.
  - info   : (optional) the info message to display.
  - error  : (optional) the error message to display.
  - thread : the thread to display.

  The thread is displayed inside a div element with the ID "#thread_{{ thread.key.id }}".
  
  Created on 2008-05-23.
  $Id: thread.html 252 2008-10-28 11:06:08Z heavyzheng $
-->
{% endcomment %}


<div id="thread_{{ thread.key.id }}" class="post">

  {% if error %}
    <div class="error message">
      {{ error }}
      <a href="javascript:void(0);" onclick="closeMessage();">[close]</a>
    </div><!--/.error-->
  {% endif %}
  
  {% if info %}
    <div class="info message">
      {{ info }}
      <a href="javascript:void(0);" onclick="closeMessage();">[close]</a>
    </div><!--/.info-->
  {% endif %}
  
  
  {% if thread %}
  
    {#--------------------------------------------------------------------------------------------#}
    {# Thread title                                                                               #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="thread-title">
      {{ thread.title }}
    </div><!--/.thread-title-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Post header                                                                                #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="post-header">
      <a href="#TODO"><b>{{ thread.author.nickname }}</b></a>
      wrote at {{ thread.post_date|date:"Y-m-d h:i:s A" }}:
    </div><!--/.post-header-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Post content                                                                               #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="post-content">
      {{ thread.content|escape|linebreaks }}
    </div><!--/.post-content-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Post attachment                                                                            #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="post-attachment">
    
      {% if thread.attachment %}
      
        <img src="/static/forum/images/attachment_icon.png" alt="Attachment"/>
        Attachment:
        <a href="/forum/attachment/{{ thread.attachment.key.id }}/">
          {{ thread.attachment.file_name }}
        </a>
        (mime-type: {{ thread.attachment.mime_type }}; size: {{ thread.attachment.size }})
        
        {% if thread.attachment.is_image %}
          <div>
            <img class="post-attachment-image"
                 src="/forum/attachment/{{ thread.attachment.key.id }}/"
                 alt="Attachment: {{ thread.attachment.file_name }}" />
          </div>
        {% endif %}
      
      {% endif %}{# thread.attachment #}
    
    </div><!--/.post-attachment-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Post information                                                                           #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="post-info">
      {% if thread.edit_date %}
        <img src="/static/forum/images/edited_icon.png" alt="Edited"/>
        This thread was edited by the author at {{ thread.edit_date|date:"Y-m-d h:i:s A" }}.
        <br/>
      {% endif %}
      {% if thread.is_recommended %}
        <img src="/static/forum/images/recommended_icon.png" alt="Recommended"/>
        This thread is recommended until {{ thread.recommended_till|date:"Y-m-d h:i:s A" }}.
        <br/>
      {% endif %}
      {% if thread.is_locked %}
        <img src="/static/forum/images/locked_icon.png" alt="Locked"/>
        This thread is locked.
        <br/>
      {% endif %}
    </div><!--/.post-info-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Toggles                                                                                    #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="form-toggles">
    
      {% if not thread.is_locked %}
        <a href="javascript:void(0);" onclick="showReplyForm('#thread_{{ thread.key.id }}');">
          <img src="/static/forum/images/reply_icon.png" alt="Reply"/>
          Reply
        </a>
      {% endif %}
      
      {% if thread.is_current_user_author %}
        <a href="javascript:void(0);" onclick="showEditForm('#thread_{{ thread.key.id }}');">
          <img src="/static/forum/images/edit_icon.png" alt="Edit"/>
          Edit
        </a>
      {% endif %}
      
      {% if thread.board.is_current_user_manager %}
        <a href="javascript:void(0);" onclick="showRecommendForm('#thread_{{ thread.key.id }}');">
          {% if thread.is_recommended %}
            <img src="/static/forum/images/unrecommend_icon.png" alt="Recommend"/>
            Unrecommend
          {% else %}
            <img src="/static/forum/images/recommend_icon.png" alt="Recommend"/>
            Recommend
          {% endif %}
        </a>
      {% endif %}
      
      {% if thread.board.is_current_user_manager %}
        <a href="javascript:void(0);" onclick="showLockForm('#thread_{{ thread.key.id }}');">
          {% if thread.is_locked %}
            <img src="/static/forum/images/unlock_icon.png" alt="Lock"/>
            Unlock
          {% else %}
            <img src="/static/forum/images/lock_icon.png" alt="Lock"/>
            Lock
          {% endif %}
        </a>
      {% endif %}
      
      {% if thread.is_current_user_author or thread.board.is_current_user_manager %}  
        <a href="javascript:void(0);" onclick="showDeleteForm('#thread_{{ thread.key.id }}');">
          <img src="/static/forum/images/delete_icon.png" alt="Delete"/>
          Delete
        </a>
      {% endif %}
    
    </div><!--/.form-toggles-->
    
    {#--------------------------------------------------------------------------------------------#}
    {# Reply thread                                                                               #}
    {#--------------------------------------------------------------------------------------------#}
    
    {% if not thread.is_locked %}
      {% if user %}
        <form class="reply-form form hidden"
              action="/forum/thread/{{ thread.key.id }}/add_reply/"
              method="POST"
              enctype="multipart/form-data">
          <p>
            <b>Title:</b><br/>
            <input name="title" type="text" size="80"/>
          <p>
            <b>Content:</b><br/>
            <textarea name="content" rows="10" cols="80"></textarea>
          </p>
          <!--p>
            <b>Attachment:</b><br/>
            <input name="attachment" type="file" size="60"/>
          </p-->
          <p>
            <input type="button" value="Submit" onclick="submitReplyForm('#thread_{{ thread.key.id }}');"/>
            <input type="button" value="Cancel" onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
          </p>
        </form>
      {% else %}
        <div class="reply-form form hidden">
          You are not logged in. To reply a thread, you need to login first.<br/>
          <a href="{{ log_url }}">Click here to login</a>
          or
          <a href="javascript:void(0);" onclick="cancelAction('#thread_{{ thread.key.id }}');">cancel</a>.
        </div>
      {% endif %}
    
    {% endif %}{# not thread.is_locked #}
  
    
    {#--------------------------------------------------------------------------------------------#}
    {# Edit post                                                                                  #}
    {#--------------------------------------------------------------------------------------------#}
    
    {% if thread.is_current_user_author %}
      <form class="edit-form form hidden"
            action="/forum/thread/{{ thread.key.id }}/edit/"
            method="POST"
            enctype="multipart/form-data">
        <p>
          <b>Title:</b><br/>
          <input name="title" type="text" size="80" value="{{ thread.title|escape }}"/>
        </p>
        <p>
          <b>Content:</b><br/>
          <textarea name="content" rows="10" cols="80">{{ thread.content|escape }}</textarea>
        </p>
        
        {% comment %}{#---------------------------------------------------------------------------#}
        {% if thread.attachment %}
          <p>
            <b>
              This thread has an attachment:
              <a href="/forum/attachment/{{ thread.attachment.key.id }}/">
                {{ thread.attachment.file_name }}
              </a>
            </b>
            <br/>
            <input type="radio" name="attachment_op" value="keep" checked="checked"/>
            Keep the attachment.
            <br/>
            <input type="radio" name="attachment_op" value="delete"/>
            Delete the attachment.
            <br/>
            <input type="radio" name="attachment_op" value="replace"/>
            Replace the attachment by: <input type="file" name="attachment"/>
            <br/>
          </p>
        {% endif %}
        {% if not thread.attachment %}
          <p>
            <b>Attachment:</b>
            <br/>
            <input type="file" name="attachment"/>
          </p>
        {% endif %}
        {% endcomment %}{#------------------------------------------------------------------------#}
        
        <p>
          <input type="button" value="Submit" onclick="submitEditForm('#thread_{{ thread.key.id }}');"/>
          <input type="button" value="Cancel" onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
        </p>
      </form><!--/.edit-form-->
    {% endif %}
    
    {#--------------------------------------------------------------------------------------------#}
    {# Recommend                                                                                  #}
    {#--------------------------------------------------------------------------------------------#}
    
    {% if thread.board.is_current_user_manager %}
      <form class="recommend-form form hidden"
            action="/forum/thread/{{ thread.key.id }}/recommend/"
            method="POST">
        {% if thread.is_recommended %}
          <input type="hidden" name="days" value="-1"/>
          <p>
            This thread is recommended until {{ thread.recommended_to|date:"Y-m-d h:i:s A" }}.
            Are you sure you want to un-recommend it right now?
          </p>
          <p>
            <input type="button" value="Yes, I am sure!" onclick="submitRecommendForm('#thread_{{ thread.key.id }}');"/>
            <input type="button" value="No, keep it recommended." onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
          </p>
        {% else %}
          <p>
            Recommend this thread for
            <input type="text" name="days" value="3" size="2"/> days.
          </p>
          <p>
            <input type="button" value="Recommend the thread" onclick="submitRecommendForm('#thread_{{ thread.key.id }}');"/>
            <input type="button" value="Cancel" onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
          </p>
        {% endif %}
      </form><!--/.recommend-form-->
    {% endif %}
    
    {#--------------------------------------------------------------------------------------------#}
    {# Lock                                                                                       #}
    {#--------------------------------------------------------------------------------------------#}
    
    {% if thread.board.is_current_user_manager %}
      <form class="lock-form form hidden"
            action="/forum/thread/{{ thread.key.id }}/lock/"
            method="POST">
        {% if thread.is_locked %}
          <input type="hidden" name="lock" value="0"/>
          <p>
            This thread is currently locked. Are you sure you want to unlock it?
          </p>
          <p>
            <input type="button" value="Yes, I am sure!" onclick="submitLockForm('#thread_{{ thread.key.id }}');"/>
            <input type="button" value="No, keep it locked." onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
          </p>
        {% else %}
          <input type="hidden" name="lock" value="1"/>
          <p>
            Are you sure you want to lock this thread?
          </p>
          <p>
            <input type="button" value="Yes, lock it!" onclick="submitLockForm('#thread_{{ thread.key.id }}');"/>
            <input type="button" value="No." onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
          </p>
        {% endif %}
      </form><!--/.lock-form-->
    {% endif %}
    
    {#--------------------------------------------------------------------------------------------#}
    {# Delete                                                                                     #}
    {#--------------------------------------------------------------------------------------------#}

    {% if thread.is_current_user_author or thread.board.is_current_user_manager %}  
      <form class="delete-form form hidden"
            action="/forum/thread/{{ thread.key.id }}/delete/"
            method="POST">
        <p>
          Are you sure you want to delete this thread?
        </p>
        <p>
          <b>Note:</b> Deleting the thread will also delete all the replies.
        </p>
        <p>
          <input type="button" value="Yes, I am sure!" onclick="submitDeleteForm('#thread_{{ thread.key.id }}');"/>
          <input type="button" value="No, keep it." onclick="cancelAction('#thread_{{ thread.key.id }}');"/>
        </p>
      </form><!--/.delete-form-->
    {% endif %}
    
    {#--------------------------------------------------------------------------------------------#}
    {# Submitting...                                                                              #}
    {#--------------------------------------------------------------------------------------------#}
    
    <div class="submitting hidden">
      <img src="/static/forum/images/waiting.gif" alt="Submitting"/>
      Submitting your request... Please wait...
    </div><!--/.submitting-->
  
  {% endif %}{# thread #}


</div><!--/#thread_{{ thread.key.id }}-->






